package org.catspaw.cherubim.security.ss3;

import org.catspaw.cherubim.security.Subject;
import org.catspaw.cherubim.security.SubjectManager;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class SpringSecuritySubjectManager implements SubjectManager {

	public Subject getCurrentSubject() {
		SecurityContext context = SecurityContextHolder.getContext();
		Authentication auth = context.getAuthentication();
		if (auth != null) {
			Object principal = auth.getPrincipal();
			if (principal instanceof Subject) {
				return (Subject) principal;
			}
		}
		return null;
	}
}
